<?php
/////////// includes
include ("vipconfig.php");
include ("rcon.class.php");
include ("./viptranslations/$lang.php");
///////////

mysql_connect($db_host, $db_user, $db_pass) or
die("Could not connect: " . mysql_error());
mysql_select_db($db_base);

$now = time();
$till = $now + $left;

$table = $sbprefix . '_admins';
$query = "SELECT `aid`,`authid`,`till` FROM `$table` WHERE `srv_group` = '$vip'";
$result = mysql_query($query);


if ($result) {
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $t_aid = $row[0];
        $t_steamid = $row[1];
        $t_till = intval($row[2]);
        if (($t_till < time()) && ($t_aid > 0) && ($t_steamid != "")) {
            //delete DELETE FROM `sb_admins` WHERE 1
            $query2 = "UPDATE `$steamidstable` SET `timeleft` = '0' WHERE `steamid` = '$t_steamid'";
            $result2 = mysql_query($query2);

            $table = $sbprefix . '_admins';
            $query2 = "DELETE FROM `$table` WHERE `aid` = '$t_aid'";
            $result2 = mysql_query($query2);
            $table = $sbprefix . '_admins_servers_groups';
            $query2 = "DELETE FROM `$table` WHERE `admin_id` = '$t_aid'";
            $result2 = mysql_query($query2);
            $diff = $now - $t_till;
            echo "deleted admin with id $t_aid and steam $t_steamid that was till $t_till\n because now $now and diff = $diff";
        }
    }
}

//update data on the server
$r = new rcon($serverip, $serverport, $serverrconpass);
$r->Auth();
$status = $r->rconCommand($racom);
$status = $r->rconCommand($rdcom);
?>